//
//  NWInitializeVersion.m
//  NiuNiuLawyer
//
//  Created by 曾永强 on 3/9/16.
//  Copyright © 2016 Beyondsoft. All rights reserved.
//

#import "NWInitializeVersionModel.h"

@implementation NWInitializeVersionModel
- (void)update
{
    if (self.appVersion.length == 0)
    {
        return;
    }
    BOOL deleteSucc = [[Singleton shareInstance].publicDB executeUpdate:@"DELETE FROM appVersion"];
    if (!deleteSucc)
    {
        NSLog(@"删除失败");
    }
    //保存
    NSString *insertSQL = [NSString stringWithFormat:@"INSERT INTO appVersion (downloadUrl,uploadTime,appVersion) VALUES ('%@','%@','%@')", self.downloadUrl,self.uploadTime,self.appVersion];
    BOOL insertSucc = [[Singleton shareInstance].publicDB executeUpdate:insertSQL];
    if (!insertSucc) {
        NSLog(@"添加失败");
    }
}

+ (NWInitializeVersionModel *)getLocalVersionModel
{
    NWInitializeVersionModel *model = nil;
    FMResultSet *rs = [[Singleton shareInstance].publicDB executeQuery:@"SELECT * FROM appVersion limit 1"];
    while ([rs next]) {
        NSDictionary *dic = [rs resultDictionary];
        model = [[NWInitializeVersionModel alloc] initWithDictionary:dic error:nil];
    }
    return model;

}
@end
